package cc.rengu.igas.bomp.biz.service.impl;

import cc.rengu.igas.bomp.common.enums.RespCodeEnum;
import cc.rengu.igas.bomp.facade.BompMchntInspectService;
import cc.rengu.igas.bomp.facade.request.*;
import cc.rengu.igas.bomp.facade.response.*;
import cc.rengu.igas.bomp.facade.result.Result;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.DubboResult;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;

/**
 * Created by zhangxuran on 2020/04/02
 */
public class BompMchntInspectServiceImpl implements BompMchntInspectService {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());

    @Override
    public Result<MchntInspectNoticeResponse> mchntInspectNotice(MchntInspectNoticeRequest mchntInspectNoticeRequest) {
        {
            DubboService dubboService = new DubboServiceImpl();
            Result<MchntInspectNoticeResponse> result = new Result<>();
            MchntInspectNoticeResponse mchntInspectNoticeResponse = new MchntInspectNoticeResponse();
            try {
                DubboResult dubboResult = dubboService.callBizService(mchntInspectNoticeRequest, MchntInspectNoticeResponse.class);
                result.setSuccess(dubboResult.isSuccess());
                result.setResult((MchntInspectNoticeResponse) dubboResult.getResult());
            } catch (Exception e) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
                rglog.error("发送商户巡检通知处理失败:<{}>", byteArrayOutputStream.toString());
                result.setSuccess(false);
                if (e instanceof BizException) {
                    mchntInspectNoticeResponse.setRespCode(((BizException) e).getCode());
                    mchntInspectNoticeResponse.setRespDesc(e.getMessage());
                } else {
                    mchntInspectNoticeResponse.setRespCode(RespCodeEnum.SYSTEM_ERROR.getRespCode());
                    mchntInspectNoticeResponse.setRespDesc(RespCodeEnum.SYSTEM_ERROR.getRespDesc());
                }
            }
            return result;
        }
    }

    @Override
    public Result<MchntInspectTaskListQueryResponse> mchntInspectTaskListQuery(MchntInspectTaskListQueryRequest mchntInspectTaskListQueryRequest) {
        {
            DubboService dubboService = new DubboServiceImpl();
            Result<MchntInspectTaskListQueryResponse> result = new Result<>();
            MchntInspectTaskListQueryResponse mchntInspectTaskListQueryResponse = new MchntInspectTaskListQueryResponse();
            try {
                DubboResult dubboResult = dubboService.callBizService(mchntInspectTaskListQueryRequest, MchntInspectTaskListQueryResponse.class);
                result.setSuccess(dubboResult.isSuccess());
                result.setResult((MchntInspectTaskListQueryResponse) dubboResult.getResult());
            } catch (Exception e) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
                rglog.error("商户巡检任务列表查询处理失败:<{}>", byteArrayOutputStream.toString());
                result.setSuccess(false);
                if (e instanceof BizException) {
                    mchntInspectTaskListQueryResponse.setRespCode(((BizException) e).getCode());
                    mchntInspectTaskListQueryResponse.setRespDesc(e.getMessage());
                } else {
                    mchntInspectTaskListQueryResponse.setRespCode(RespCodeEnum.SYSTEM_ERROR.getRespCode());
                    mchntInspectTaskListQueryResponse.setRespDesc(RespCodeEnum.SYSTEM_ERROR.getRespDesc());
                }
            }
            return result;
        }
    }

    @Override
    public Result<InspectTaskMchntListQueryResponse> needInspectMchntListQuery(InspectTaskMchntListQueryRequest inspectTaskMchntListQueryRequest) {
        {
            DubboService dubboService = new DubboServiceImpl();
            Result<InspectTaskMchntListQueryResponse> result = new Result<>();
            InspectTaskMchntListQueryResponse needInspectMchntListQueryResponse = new InspectTaskMchntListQueryResponse();
            try {
                DubboResult dubboResult = dubboService.callBizService(inspectTaskMchntListQueryRequest, InspectTaskMchntListQueryResponse.class);
                result.setSuccess(dubboResult.isSuccess());
                result.setResult((InspectTaskMchntListQueryResponse) dubboResult.getResult());
            } catch (Exception e) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
                rglog.error("新建商户巡检任务商户列表查询处理失败:<{}>", byteArrayOutputStream.toString());
                result.setSuccess(false);
                if (e instanceof BizException) {
                    needInspectMchntListQueryResponse.setRespCode(((BizException) e).getCode());
                    needInspectMchntListQueryResponse.setRespDesc(e.getMessage());
                } else {
                    needInspectMchntListQueryResponse.setRespCode(RespCodeEnum.SYSTEM_ERROR.getRespCode());
                    needInspectMchntListQueryResponse.setRespDesc(RespCodeEnum.SYSTEM_ERROR.getRespDesc());
                }
            }
            return result;
        }
    }

    @Override
    public Result<InspectTaskDetailListQueryResponse> inspectTaskDetailListQuery(InspectTaskDetailListQueryRequest inspectTaskDetailListQueryRequest) {
        {
            DubboService dubboService = new DubboServiceImpl();
            Result<InspectTaskDetailListQueryResponse> result = new Result<>();
            InspectTaskDetailListQueryResponse inspectTaskDetailListQueryResponse = new InspectTaskDetailListQueryResponse();
            try {
                DubboResult dubboResult = dubboService.callBizService(inspectTaskDetailListQueryRequest, InspectTaskDetailListQueryResponse.class);
                result.setSuccess(dubboResult.isSuccess());
                result.setResult((InspectTaskDetailListQueryResponse) dubboResult.getResult());
            } catch (Exception e) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
                rglog.error("巡检任务详情列表查询处理失败:<{}>", byteArrayOutputStream.toString());
                result.setSuccess(false);
                if (e instanceof BizException) {
                    inspectTaskDetailListQueryResponse.setRespCode(((BizException) e).getCode());
                    inspectTaskDetailListQueryResponse.setRespDesc(e.getMessage());
                } else {
                    inspectTaskDetailListQueryResponse.setRespCode(RespCodeEnum.SYSTEM_ERROR.getRespCode());
                    inspectTaskDetailListQueryResponse.setRespDesc(RespCodeEnum.SYSTEM_ERROR.getRespDesc());
                }
            }
            return result;
        }
    }

    @Override
    public Result<MchntInspectInfoQueryResponse> mchntInspectInfoQuery(MchntInspectInfoQueryRequest mchntInspectInfoQueryRequest) {
        {
            DubboService dubboService = new DubboServiceImpl();
            Result<MchntInspectInfoQueryResponse> result = new Result<>();
            MchntInspectInfoQueryResponse mchntInspectInfoQueryResponse = new MchntInspectInfoQueryResponse();
            try {
                DubboResult dubboResult = dubboService.callBizService(mchntInspectInfoQueryRequest, MchntInspectInfoQueryResponse.class);
                result.setSuccess(dubboResult.isSuccess());
                result.setResult((MchntInspectInfoQueryResponse) dubboResult.getResult());
            } catch (Exception e) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
                rglog.error("商户巡检信息详情查询处理失败:<{}>", byteArrayOutputStream.toString());
                result.setSuccess(false);
                if (e instanceof BizException) {
                    mchntInspectInfoQueryResponse.setRespCode(((BizException) e).getCode());
                    mchntInspectInfoQueryResponse.setRespDesc(e.getMessage());
                } else {
                    mchntInspectInfoQueryResponse.setRespCode(RespCodeEnum.SYSTEM_ERROR.getRespCode());
                    mchntInspectInfoQueryResponse.setRespDesc(RespCodeEnum.SYSTEM_ERROR.getRespDesc());
                }
            }
            return result;
        }
    }

    @Override
    public Result<MchntInspectInfoManagerResponse> mchntInspectInfoManager(MchntInspectInfoManagerRequest mchntInspectInfoManagerRequest) {
        {
            DubboService dubboService = new DubboServiceImpl();
            Result<MchntInspectInfoManagerResponse> result = new Result<>();
            MchntInspectInfoManagerResponse mchntInspectInfoManagerResponse = new MchntInspectInfoManagerResponse();
            try {
                DubboResult dubboResult = dubboService.callBizService(mchntInspectInfoManagerRequest, MchntInspectInfoManagerResponse.class);
                result.setSuccess(dubboResult.isSuccess());
                result.setResult((MchntInspectInfoManagerResponse) dubboResult.getResult());
            } catch (Exception e) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
                rglog.error("商户巡检信息管理询处理失败:<{}>", byteArrayOutputStream.toString());
                result.setSuccess(false);
                if (e instanceof BizException) {
                    mchntInspectInfoManagerResponse.setRespCode(((BizException) e).getCode());
                    mchntInspectInfoManagerResponse.setRespDesc(e.getMessage());
                } else {
                    mchntInspectInfoManagerResponse.setRespCode(RespCodeEnum.SYSTEM_ERROR.getRespCode());
                    mchntInspectInfoManagerResponse.setRespDesc(RespCodeEnum.SYSTEM_ERROR.getRespDesc());
                }
            }
            return result;
        }
    }

    @Override
    public Result<MchntInspectListQueryResponse> mchntInspectListQuery(MchntInspectListQueryRequest mchntInspectListQueryRequest) {
        {
            DubboService dubboService = new DubboServiceImpl();
            Result<MchntInspectListQueryResponse> result = new Result<>();
            MchntInspectListQueryResponse mchntInspectListQueryResponse = new MchntInspectListQueryResponse();
            try {
                DubboResult dubboResult = dubboService.callBizService(mchntInspectListQueryRequest, MchntInspectListQueryResponse.class);
                result.setSuccess(dubboResult.isSuccess());
                result.setResult((MchntInspectListQueryResponse) dubboResult.getResult());
            } catch (Exception e) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
                rglog.error("商户巡检记录查询请求类处理失败:<{}>", byteArrayOutputStream.toString());
                result.setSuccess(false);
                if (e instanceof BizException) {
                    mchntInspectListQueryResponse.setRespCode(((BizException) e).getCode());
                    mchntInspectListQueryResponse.setRespDesc(e.getMessage());
                } else {
                    mchntInspectListQueryResponse.setRespCode(RespCodeEnum.SYSTEM_ERROR.getRespCode());
                    mchntInspectListQueryResponse.setRespDesc(RespCodeEnum.SYSTEM_ERROR.getRespDesc());
                }
            }
            return result;
        }
    }
}
